package emulador;
public class Instruccion {

    private int d;
    private int n;
    private int opcode;
    private int r;

    public Instruccion(int opcode, int n, int d, int r) {
            this.opcode = opcode;
            this.n = n;
            this.d = d;
            this.r = r;
    }

    public int getOperand() {
            return d;
    }

    public int getOpcode() {
            return opcode;
    }

    public int getRegister() {
            return r;
    }

    public int getSize() {
            return n;
    }

    public String toString() {
            StringBuilder sb = new StringBuilder();

            switch (opcode) {
            case SAM.INST_LOAD:
                    sb.append("LOAD (" + n + ") " + d + "[" + r + "]");
                    break;
            case SAM.INST_LOADA:
                    sb.append("LOADA " + d + "[" + r + "]");
                    break;
            case SAM.INST_LOADI:
                    sb.append("LOADI (" + n + ")");
                    break;
            case SAM.INST_LOADL:
                    sb.append("LOADL " + d);
                    break;
            case SAM.INST_STORE:
                    sb.append("STORE (" + n + ") " + d + "[" + r + "]");
                    break;
            case SAM.INST_STOREI:
                    sb.append("STOREI (" + n + ")");
                    break;
            case SAM.INST_CALL:
                    sb.append("CALL (" + n + ") " + d + "[" + r + "]");
                    break;
            case SAM.INST_CALLI:
                    sb.append("CALLI");
                    break;
            case SAM.INST_RETURN:
                    sb.append("RETURN (" + n + ") " + d);
                    break;
            case SAM.INST_PUSH:
                    sb.append("PUSH " + d);
                    break;
            case SAM.INST_POP:
                    sb.append("POP (" + n + ") " + d);
                    break;
            case SAM.INST_JUMP:
                    sb.append("JUMP " + d + "[" + r + "]");
                    break;
            case SAM.INST_JUMPI:
                    sb.append("JUMPI ");
                    break;
            case SAM.INST_JUMPIF:
                    sb.append("JUMPIF (" + n + ") " + d + "[" + r + "]");
                    break;
            case SAM.INST_HALT:
                    sb.append("HALT");
                    break;
            default:
                    sb.append("ILLEGAL OPERATION");
                    break;
            }

            return sb.toString();
    }
}
